package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.CategoryService;
import cn.kshost.zqyg.model.entity.product.Category;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import com.alibaba.excel.EasyExcel;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.URLEncoder;
import java.util.List;

@RequestMapping("/admin/system/Category")
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "根据父ID查询列表")
    @GetMapping("/getCategoryListByParentId/{parentId}")
    public Result<List<Category>>  getCategoryListByParentId(@PathVariable int parentId) {
    List<Category> categories =  categoryService.getCategoryListByParentId(parentId);
    return Result.build(categories, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "导出分类Excle")
    @GetMapping("/exportExcel")
    public void exportExcel(  HttpServletResponse response) {
        categoryService.exportExcel(response);
    }

    @PostMapping("/importExcel")
    public Result<String> importExcel(MultipartFile file) {
        categoryService.importExcel(file);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
